//去重 数组
export function duplicate(arr){
    if (!Array.isArray(arr)) {
        return;
    }
    var array = [];
    for (var i = 0; i < arr.length; i++) {

        if (array .indexOf(arr[i]) === -1) {

            array .push(arr[i])

        }

    }

    return array;

}
export function calculateDistance(lat1, lon1, lat2, lon2) {
    const radius = 6371; // 地球半径，单位为公里

    const deltaLat = (lat2 - lat1) * (Math.PI / 180);
    const deltaLon = (lon2 - lon1) * (Math.PI / 180);

    lat1 = lat1 * (Math.PI / 180);
    lat2 = lat2 * (Math.PI / 180);

    const a = Math.sin(deltaLat / 2) * Math.sin(deltaLat / 2) +
              Math.cos(lat1) * Math.cos(lat2) *
              Math.sin(deltaLon / 2) * Math.sin(deltaLon / 2);
    const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    const distance = radius * c;

    return distance;
  }
  export function getOffsetDays(startDate, endDate){
    var startDateArr = startDate.split("-");
    var checkStartDate = new Date();
    checkStartDate.setFullYear(startDateArr[0], startDateArr[1], startDateArr[2]);
    var endDateArr = endDate.split("-");
    var checkEndDate = new Date();
    checkEndDate.setFullYear(endDateArr[0], endDateArr[1], endDateArr[2]);
    var days = (checkEndDate.getTime() - checkStartDate.getTime())/ 3600000 / 24;
    // if(startDateArr[0]!=endDateArr[0]){
    //   flag = true;
    // }
    return days;
 }
